<?php
require_once("../../Config.php");
require_once("../../Class/ClassMysql.php");
require_once("../../Class/ClassCheck.php");
require_once("../../Class/ClassResult.php");

//json头
header("Content-type: application/json");

session_start();
if(!isset($_SESSION["name"])) {
    exit(Result::jsonReturn(1, "未登录"));
}

$uid = $_SESSION["id"];
$uname = $_SESSION["name"];
$uemail = $_SESSION["email"];
$upower = $_SESSION["power"];


if((int)$upower == 0) {
    exit(Result::jsonReturn(1, "权限不足"));
}

$db = new DB();
if(!Check::isEmpty($_GET["id"])) {
    if(Check::isNum($_GET["id"]) && (int)$_GET["id"]>0) {
        $id = (int)$_GET["id"];
        $sql = "SELECT * FROM qilian_users WHERE id={$id}";
        $res = array();
        if($res = $db->getOne($sql)) {
            exit(Result::jsonReturn(0, "查询成功", $res));
        }else {
            exit(Result::jsonReturn(1, "查询失败"));
        }
    }else {
        exit(Result::jsonReturn(1, "参数格式有误"));
    }
}else {
    $sql = "SELECT id, name, email, power FROM qilian_users ORDER BY id DESC";
    $res = array();
    if($res=$db->getAll($sql)) {
        exit(Result::jsonReturn(0, "读取所有用户成功", $res));
    }else {
        exit(Result::jsonReturn(1, "读取所有用户失败"));
    }    
}


?>